package com.pi.pro.xcmg.am.was.edi.sap.common;


import com.pi.framework.core.util.DateUtils;
import com.pi.framework.core.util.StringUtils;
import com.pi.pro.xcmg.am.was.edi.sap.dto.reply.DeliveryNoteData;
import com.pi.pro.xcmg.am.was.edi.sap.dto.reply.DeliveryNoteReplyData;

import java.util.Date;

public class SapWasXcmgExchangeSupport {

    public static final DeliveryNoteReplyData blankOk(){
        DeliveryNoteReplyData replyData=new DeliveryNoteReplyData();
        replyData.setReturnCode(SapWasXcmgExchangeConstants.RESULT_CODE_OK);
        replyData.setReturnMsg("");
        replyData.setOpstmp(DateUtils.format(new Date(), DateUtils.FORMAT_DATE_YYYY_MM_DD_HHMMSS));
        return replyData;
    }

    public static final String check(DeliveryNoteReplyData replyData){
        String m = "";
        if (replyData==null){
            m = "未接收到SAP反馈,请确认连接正常.";
            return m;
        }
        if (StringUtils.isNullOrBlank(replyData.getReturnCode())){
            m = "SAP反馈状态为空";
            return m;
        }
        if (!SapWasXcmgExchangeConstants.RESULT_CODE_OK.equalsIgnoreCase(replyData.getReturnCode())){
            m = "获取SAP配送指令异常.错误信息:"+replyData.getReturnMsg();
            return m;
        }
        return m;
    }

    public static final Date lastCheck(DeliveryNoteReplyData replyData){
        Date date=null;
        String m = check(replyData);
        if (!StringUtils.isNullOrBlank(m)){
            return date;
        }
        //20250126100000
        try{
            date=DateUtils.parse(replyData.getOpstmp(), DateUtils.FORMAT_DATE_YYYY_MM_DD_HHMMSS);
        }catch (Exception e){
            e.printStackTrace();
        }
        return date;
    }

    public static final boolean isDelete(DeliveryNoteData deliveryNoteData){
        if (deliveryNoteData==null){
            return false;
        }
        if (deliveryNoteData.getZztsc()==null){
            return false;
        }
        if (!SapWasXcmgExchangeConstants.DOC_LINE_PROCESS_DEL_FLAG_YES.equalsIgnoreCase(deliveryNoteData.getZztsc())){
            return false;
        }
        return true;
    }

    public static final boolean isClose(DeliveryNoteData deliveryNoteData){
        if (deliveryNoteData==null){
            return false;
        }
        if (deliveryNoteData.getZztgb()==null){
            return false;
        }
        if (!SapWasXcmgExchangeConstants.DOC_LINE_PROCESS_CLOSE_FLAG_YES.equalsIgnoreCase(deliveryNoteData.getZztgb())){
            return false;
        }
        return true;
    }
}
